﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TimbreRecognition.FeatureExtraction
{
    public class DataItemWritter
    {
        private const string Delemiter = " ";

        private const string InputCount = "input_count";

        private const string OutputCount = "output_count";

        private const string TotalCount = "total_count";

        public void Write(string file, List<DataItem> dataItems)
        {
            StreamWriter writer = new StreamWriter(file);

            writer.WriteLine(InputCount + "=" + dataItems[0].InputCount);
            writer.WriteLine(OutputCount + "=" + dataItems[0].OutputCount);
            writer.WriteLine(TotalCount + "=" + dataItems.Count);

            foreach (var dataItem in dataItems)
            {
               foreach (double input in dataItem.DataSeries)
               {
                   writer.Write(input.ToString("F8"));
                   writer.Write(Delemiter);
               }

               foreach (var output in dataItem.ExpectedOutput)
               {
                   writer.Write(output.ToString("F0"));
                   writer.Write(Delemiter);
               }

               writer.Write(Environment.NewLine);
            }

            writer.Close();
        }
    }
}
